<?php

$rewrite = function_exists('apache_get_modules') && in_array('mod_rewrite', apache_get_modules());;

if( $panel['layer'])
	$nodes = db()->query("SELECT node.*
		FROM content_layer AS node
		JOIN content_layer AS parent
		ON node.lft BETWEEN parent.lft + 1 AND parent.rgt - 1
		WHERE parent.id = %d", $panel['layer'] )->objects('id');
else
	$nodes = db()->content_layer->all()->objects('id');

foreach( $nodes as $node ) {
	$node->link = $rewrite ? urldecode($node->name) : IV_SELF.'page='.$node->id;
	if( empty( $nodes[$node->parent] )) $panel['menu'][] = $node;
	else $nodes[$node->parent]->children[] = $node;
}
